package com.audaque.springboot.foshanupload.web.httpclientdemo.ieg.product;

import cn.hutool.core.net.url.UrlBuilder;
import com.audaque.springboot.foshanupload.web.httpclientdemo.ieg.IegProperties;
import com.audaque.springboot.foshanupload.web.httpclientdemo.ieg.model.HutoolRequest;
import com.audaque.springboot.foshanupload.web.httpclientdemo.ieg.product.model.IegReferUrl;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @author zgb
 * @desc ...
 * @date 2022-04-17 19:01:59
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Component
@ConfigurationProperties(prefix = "ieg.product")
public class IegProductProperties extends IegProperties {

    private String baseUrl;
    private HutoolRequest insert;
    private HutoolRequest update;
    private HutoolRequest one;
    private String sync2Db;

    private IegReferUrl referUrl;

    public String referUrl(String id) {
        String path = referUrl.getDetail().getPath().replace("{id}", id);
        return UrlBuilder.create().setScheme(referUrl.getScheme()).setHost(referUrl.getHost()).addPath(path).setCharset(null).build();
    }

    public String getOneUrl(String id) {
        String path = one.getPath().replace("{id}", id);
        return UrlBuilder.create().setScheme(super.getScheme()).setHost(super.getHost()).addPath(path).build();
    }

    public String getInsertUrl( ) {
        return UrlBuilder.create().setScheme(super.getScheme()).setHost(super.getHost()).addPath(insert.getPath()).build();
    }

    public String getUpdateUrl(String id) {
        String path = update.getPath().replace("{id}", id);
        return UrlBuilder.create().setScheme(super.getScheme()).setHost(super.getHost()).addPath(path).build();
    }

}
